/**
 * Copyright(c) 2013 Hitachi All rights reserved.
 */
package cn.com.dhc.mibd.eufw.widget.android.widget;

import android.view.LayoutInflater;
import android.widget.BaseAdapter;

import java.util.List;

public abstract class AbstractGridAdapter <Item> extends BaseAdapter {

    /**
     * activity
     */
    protected AbstractGridView gridView = null;

    /**
     * item list
     */
    protected List<Item> itemList = null;

    /**
     * inflater
     */
    protected LayoutInflater inflater;

    //    public AbstractGridAdapter(AbstractGridView gridView, List<Item> model) {
    //        super();
    //        this.gridView = gridView;
    //        this.itemList = model;
    //        inflater = LayoutInflater.from(gridView.getDelegate().getActivity());
    //    }

    public AbstractGridAdapter(AbstractGridView gridView, List<Item> model) {
        super();
        this.gridView = gridView;
        this.itemList = model;
        inflater = LayoutInflater.from(gridView.getContext());
    }

    @Override
    public int getCount() {
        return (itemList == null) ? 0 : itemList.size();
    }

    @Override
    public Object getItem(int position) {
        return itemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public boolean isEmpty() {
        return (itemList == null) || itemList.isEmpty();
    }

    public AbstractGridView getGridView() {
        return gridView;
    }

    public List<Item> getItemList() {
        return itemList;
    }
}
